package com.example.demo.generator.codegen.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Simplified class description produced by the SQL parser adapter.
 */
public class ClassInfo {

    /**
     * 去前缀后的表名。
     */
    private String tableName;
    /**
     * 原始表名。
     */
    private String originTableName;
    /**
     * 生成的类名。
     */
    private String className;
    /**
     * 表或 SQL 备注信息。
     */
    private String classComment;
    /**
     * 字段定义集合。
     */
    private List<FieldInfo> fieldList = new ArrayList<>();
    /**
     * 主键列名称集合，保持声明顺序。
     */
    private List<String> primaryKeyColumns = new ArrayList<>();
    /**
     * 表级索引/约束信息。
     */
    private List<IndexInfo> indexList = new ArrayList<>();

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getOriginTableName() {
        return originTableName;
    }

    public void setOriginTableName(String originTableName) {
        this.originTableName = originTableName;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getClassComment() {
        return classComment;
    }

    public void setClassComment(String classComment) {
        this.classComment = classComment;
    }

    public List<FieldInfo> getFieldList() {
        return fieldList;
    }

    public void setFieldList(List<FieldInfo> fieldList) {
        this.fieldList = fieldList;
    }

    public List<String> getPrimaryKeyColumns() {
        return primaryKeyColumns;
    }

    public void setPrimaryKeyColumns(List<String> primaryKeyColumns) {
        this.primaryKeyColumns = primaryKeyColumns != null ? primaryKeyColumns : new ArrayList<>();
    }

    public List<IndexInfo> getIndexList() {
        return indexList;
    }

    public void setIndexList(List<IndexInfo> indexList) {
        this.indexList = indexList != null ? indexList : new ArrayList<>();
    }

    @Override
    public String toString() {
        return "ClassInfo{" +
                "tableName='" + tableName + '\'' +
                ", originTableName='" + originTableName + '\'' +
                ", className='" + className + '\'' +
                ", classComment='" + classComment + '\'' +
                ", fieldList=" + fieldList +
                ", primaryKeyColumns=" + primaryKeyColumns +
                ", indexList=" + indexList +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof ClassInfo)) {
            return false;
        }
        ClassInfo classInfo = (ClassInfo) o;
        return Objects.equals(tableName, classInfo.tableName)
                && Objects.equals(originTableName, classInfo.originTableName)
                && Objects.equals(className, classInfo.className)
                && Objects.equals(classComment, classInfo.classComment)
                && Objects.equals(fieldList, classInfo.fieldList)
                && Objects.equals(primaryKeyColumns, classInfo.primaryKeyColumns)
                && Objects.equals(indexList, classInfo.indexList);
    }

    @Override
    public int hashCode() {
        return Objects.hash(tableName, originTableName, className, classComment, fieldList, primaryKeyColumns, indexList);
    }
}
